<?php

/**
 * @url http://localhost/leetcode/leetcode-score.php
 * @since 2024-09-03 难度分数据，https://raw.githubusercontent.com/zerotrac/leetcode_problem_rating/main/data.json
 */

/**
 * @since 2024-09-03 获取原始数据
 */
$url = "https://raw.githubusercontent.com/zerotrac/leetcode_problem_rating/main/data.json";
$dataArray = json_decode(file_get_contents($url), true);

/**
 * @since 2024-09-03 简化数据
 */
foreach ($dataArray as $k=>$dArray){
    $dArray["Rating"] = intval($dArray["Rating"]);

    /**
     * @since 2024-12-05 记录周赛序号
     * @since 2024-12-05 是否双周赛
     * @since 2024-12-05 应该在js里格式化统一处理
     */
    // $dArray["contestID"] = explode(" ", $dArray["ContestID_en"])[2];
    // $dArray["biweekly"] = (substr($dArray["ContestID_en"], 0, 8) == "Biweekly") ? 1 : 0;
    // unset($dArray["ID"], $dArray["Title"], $dArray["TitleZH"], $dArray["ContestID_en"], $dArray["ContestID_zh"]);
    unset($dArray["ID"], $dArray["Title"], $dArray["TitleZH"], $dArray["ContestID_zh"]);

    $dataArray[$k] = $dArray;
}

/**
 * @since 2024-12-05 输出数据量
 */
$list = [
    "rows" => count($dataArray),
    "data" => $dataArray,
];
echo json_encode($list, JSON_UNESCAPED_UNICODE);
file_put_contents("/tmp/leetcode/score.json", json_encode($dataArray, JSON_UNESCAPED_UNICODE));